﻿using KWT.DRG_DIP.API.Infrastructure;
using KWT.DRG_DIP.DB;
using KWT.DRG_DIP.PO.Basic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KWT.DRG_DIP.API.Controllers.Basic
{
    /// <summary>
    /// 部门管理
    /// </summary>
    [ApiExplorerSettings(GroupName = "basic")]
    public class DeptController : BasicControllerBase
    {
        public EFContext ef { get; set; }

        /// <summary>
        /// 部门列表（级联组件使用）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public OutputResult CascaderList()
        {
            var list = ef.Set<Sys_Dept>().Select(x => new { label = x.Name, value = x.DeptID, children = new List<string>(), loading = false, type = "dept" }).ToList();
            return Output(list.Count > 0, "", "", list);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public OutputResult List()
        {
            var list = ef.Set<Sys_Dept>().ToList();
            return Output(list.Count > 0, "", "", list);
        }
    }
}
